<template>
  <div class="login-container">
    <div class="login-left">
      <div class="title">
        高迪股份 | 智慧梁场MES
      </div>
      <div class="typer">
        <vue-typer :text='["打造国内顶尖智慧梁场MES", "全链路流程信息把控"]'
          erase-style='clear'
          :erase-on-complete='false'
        />
      </div>
      <div class="subtitle">
        提升生产管控效率、质量追溯水平和设备管理能力
      </div>
    
    </div>
    <div class="login-right">
      <div class="form">
        <div style="display:flex;justify-content: flex-start;align-items: center;">
          <el-image 
          :src="logo"
          style="width: 50px;height: 50px;margin-right: 40px;"
          >  
        </el-image>
        <div style="font-size: 18px;letter-spacing: 3px;font-weight: 600;">MES用户登录</div>
        </div>
        <el-form ref="form" :model="form" :rules="rules" style="margin-top:40px;">
          <el-form-item prop="account">
            <el-input v-model="form.account" class="input" placeholder="请填写账号"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model="form.password" type="password" class="input" placeholder="请填写密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-checkbox v-model="form.checked">记住账号</el-checkbox>
          </el-form-item>
          <el-button type="primary" class="login-button" @click="doLogin" :loading="lock">立即登录</el-button>
        </el-form>
      </div>
      
    </div>
  </div>
</template>

<script>  
import { VueTyper } from 'vue-typer';
import login from '@/api/login';

export default {
  name: "Login",
  components: {
    'vue-typer': VueTyper
  },
  data () {
    return {
      logo: require('@/assets/imgs/logo.png'),
      lock: false,
      form: {
        account: "",
        password: "",
        checked: false,
      },
      rules: {
        account: [
          { required: true, message: '请填写账号', trigger: 'blur' },
        ],
        password: [
          { required: true, message: '请填写密码', trigger: 'blur' }
        ]
      },
      redirect: '/'
    }
  },
  mounted() {
    if (localStorage.getItem('rememberAccount')) {
      let account = JSON.parse(localStorage.getItem('rememberAccount'));
      this.form = account;
    }
  },
  methods: {
    async doLogin() {
      if (this.lock === true) {
        return false;
      }
      let result = await login.login(this.form);
      this.lock = false;
      if (result.code === 0) {
        if (this.form.checked === true) {
          localStorage.setItem("rememberAccount", JSON.stringify(this.form));
        } else {
          localStorage.removeItem('rememberAccount');
        }
        this.$message.success(result.msg);
        this.$router.push(this.redirect);
      } else {
        this.$message.error(result.msg);
      }
      
    }
  }
}
</script>

<style lang="scss">
  .vue-typer .custom.char.typed {
    color: #FFF;
  }
  .vue-typer .custom.caret {
    display: none;
  }
  .login-container {
    width: 100%;
    height: 100%;
    background-blend-mode: multiply;
    background-image: url('~@/assets/imgs/login-background.jpg');
    background-color: rgba(0, 0, 0, 0.5);
    background-size: cover;
    background-position: 50%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    
    .login-left {
      width: calc(100% - 600px);
      margin-left: 60px;

      .title {
        font-size: 50px;
        color: #fff;
      }
      .typer {
        min-height: 80px;
        line-height: 80px;
        color: #fff;
        font-size: 65px;
        font-weight: bold;
        margin-top:40px;
      }
      .subtitle {
        color: #fff;
        font-size: 40px;
        margin-top: 20px;
      }
    }
    .login-right {
      width: 600px;
      height: 100%;
      background: rgba(3,13,32,.6);

      .form {
        width: 415px;
        margin: 50% auto;
        background: #fff;
        height: 400px;
        border-radius: 8px;
        padding: 35px 40px;
        .el-input__inner {
          border: none;
          border-bottom: 1px solid #bdc1ca;
          border-radius: 0; 
          margin: 0 auto;
        }
        .login-button {
          background: linear-gradient(250deg,#0707e6,#2a05a5);
          width: 100%;
        }
      }
    }
  }
</style>
